package com.pxmeta.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pxmeta.common.constant.Status;
import com.pxmeta.product.entity.Product;
import com.pxmeta.product.mapper.ProductMapper;
import com.pxmeta.product.service.IProductService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
@RequiredArgsConstructor
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements IProductService {
    @Override
    public List<Product> getVirtualCurrencyList() {
        LambdaQueryWrapper<Product> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(Product::getType, 1)
                .eq(Product::getStatus, Status.SUCCESS.getValue())
                .orderByAsc(Product::getRealPrice);

        return this.list(wrapper);
    }

    @Override
    public Product getByAppStoreId(String appStoreProductId) {
        LambdaQueryWrapper<Product> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(Product::getAppStoreId, appStoreProductId);
        return this.getOne(wrapper);
    }
}
